#!/usr/bin/env python

import sys,os

#posix only
def istextfile(path):
    if 'text' in os.popen('file '+path).read():
        return True
    return False

def getfiles(basedir,dir=''):
    join = os.path.join
    curpath = join(basedir,dir)
    ret = []
    for f in os.listdir(curpath):
        if os.path.isdir(join(curpath,f)):
            ret += getfiles(basedir,join(dir,f))
        else:
            ret.append(join(dir,f))
    return ret


def mkpath(fullpath):
    """
    makes all missed directory of a path
    """
    if not fullpath: return
    if fullpath[-1] == os.path.sep:
        fullpath = fullpath[:-1]
    if fullpath and not os.path.exists(fullpath):
        path = os.path.split(fullpath)[0]
        mkpath(path)
        os.mkdir(fullpath)
